// 不使用运算符 + 和 - ​​​​​​​，计算两整数 ​​​​​​​a 、b ​​​​​​​之和。

// 示例 1:

// 输入: a = 1, b = 2
// 输出: 3
// 示例 2:

// 输入: a = -2, b = 3
// 输出: 1

// 递归
class Solution1 {
public:
    int getSum(int a, int b) {
        if (b == 0) return a;
        int sum = a ^ b;
        int carry = (a & b & 0x7fffffff) << 1;
        return getSum(sum, carry);
    }
};

// 迭代
class Solution {
public:
    int getSum(int a, int b) {
        while (b) {
            int carry = (a & b & 0x7fffffff) << 1;
            a = a ^ b;
            b = carry;
        }
        return a;
    }
};

// 迭代
class Solution {
public:
    int getSum(int a, int b) {
        while (b) {
            unsigned int carry = static_cast<unsigned int>(a & b) << 1;
            a = a ^ b;
            b = carry;
        }
        return a;
    }
};